import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * uomType - 计量单位类型定义
 * @date: 2018/10/13 09:06:36

 */
import { createPagination, getResponse } from 'utils/utils';
import { fetchUomList as _fetchUomList, addUom } from "../services/uomTypeService";
export default {
  namespace: 'uomType',
  state: {
    uomList: [],
    pagination: {},
    dataSourceMap: {},
    // 选中的所有项，参考李宁
    selectedRowKeys: []
  },
  effects: {
    // 查询Uom
    fetchUomList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchUomList(_ref, _ref2) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchUomList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.t0 = getResponse;
              _context.next = 5;
              return call(_fetchUomList, payload);

            case 5:
              _context.t1 = _context.sent;
              result = (0, _context.t0)(_context.t1);

              if (!result) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  uomList: result.content,
                  pagination: createPagination(result)
                }
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, fetchUomList);
    }),
    // 新增Uom
    addUomTypes: /*#__PURE__*/_regeneratorRuntime.mark(function addUomTypes(_ref3, _ref4) {
      var payload, call, data;
      return _regeneratorRuntime.wrap(function addUomTypes$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(addUom, _objectSpread({}, payload));

            case 4:
              data = _context2.sent;
              return _context2.abrupt("return", getResponse(data));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, addUomTypes);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref5) {
      var payload = _ref5.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};